<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增用户</title>
    <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
    <script src="js/vue.js"></script>
    <script src="element-ui/lib/index.js"></script>
    <script src="js/axios-0.18.0.js"></script>
</head>
<body>
<div id="div">
    <h4>挂号</h4>
    <el-form :model="registerForm" size="mini" ref="registerForm" label-width="100px">
        <el-form-item label="身份证号">
            <el-input  v-model="registerForm.patient.idCard" @blur="loadPatientInfo()"></el-input>
        </el-form-item>
        <el-form-item label="病人姓名">
            <el-input v-model="registerForm.patient.name" disabled></el-input>
        </el-form-item>
        <el-form-item label="手机号">
            <el-input v-model="registerForm.patient.phone" disabled></el-input>
        </el-form-item>
        <el-form-item label="出生日期">
            <el-input v-model="registerForm.patient.birthday" disabled></el-input>
        </el-form-item>
        <el-form-item label="性别">
            <el-input v-model="registerForm.patient.sex" disabled></el-input>
        </el-form-item>
        <el-form-item label="家庭地址">
            <el-input  v-model="registerForm.patient.address" disabled></el-input>
        </el-form-item>
        <el-form-item label="就诊科室">
            <el-select v-model="registerForm.departmentId"  placeholder="请选择" @change="selectDepartment()">
                <el-option
                        v-for="item in departmentList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                </el-option>
            </el-select>
        </el-form-item>

        <el-form-item label="时间段"  v-if="registerForm.departmentId!=''">
            <el-select v-model="registerForm.sign"  placeholder="请选择" @change="selectSign()">
                <el-option
                        v-for="item in signList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="就诊医师" prop="userId" v-if="docterList.length>0&&registerForm.sign!=''">
            <el-select v-model="registerForm.userId"  placeholder="请选择" @change="selectDoctor()">
                <el-option
                        v-for="item in docterList"
                        :key="item.id"
                        :label="item.userName"
                        :value="item.id">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="就诊房间"  disabled v-if="registerForm.userId!=''">
            <el-input v-model="registerForm.room.name"></el-input>
        </el-form-item>

        <el-form-item label="是否医保"  v-if="registerForm.userId!=''">
            <el-radio-group v-model="registerForm.isMedicare" @change="selectMedicare">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="2">否</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="医保卡号"  v-if="registerForm.userId!=''&&this.registerForm.isMedicare==1">
            <el-input  v-model="registerForm.idMedicare"></el-input>
        </el-form-item>
        <el-form-item label="挂号总金额"  v-if="registerForm.userId!=''">
            <el-input v-model="registerForm.fee" disabled></el-input>
        </el-form-item>
        <el-form-item label="医保报销额"  v-if="registerForm.userId!=''">
            <el-input v-model="registerForm.medicareFee" disabled></el-input>
        </el-form-item>
        <el-form-item label="实际应支付"  v-if="registerForm.userId!=''">
            <el-input v-model="registerForm.payFee" disabled></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="createRegistry()">保存</el-button>
            <el-button @click="resetForm('registerForm')">返回</el-button>
        </el-form-item>
    </el-form>
</div>
</body>
<script type="application/javascript">
    new Vue({
            el: '#div',
            data: {
                registerForm: {
                    /*病人信息*/
                    patient:{
                        id:'',
                        idCard: '',
                        name: '',
                        phone: '',
                        birthday: '',
                        sex:'',
                        address: '',
                        idMedicare:''
                    },
                    scheduleId:0,/*排期编号*/
                    userId:'',/*就诊医生*/
                    departmentId:'',/*就诊科室*/
                    room:{
                    },
                    idMedicare:'',
                    sign:'',
                    status:1, /*1-->已挂号，未问诊；2-->正在问诊；3-->问诊结束',*/
                    fee:50, /*挂号总金额(￥)*/
                    payFee:10,/*实际应支付*/
                    medicareFee:40,/*医保报销费*/
                    isMedicare:2,/*是否医保*/
                },
                departmentList:[
                    {id: 1, name: '门诊内科'},
                    {id: 2, name: '门诊外科'},
                    {id: 3, name: '门诊儿科'},
                    {id: 4, name: '门诊眼科'},
                    {id: 5, name: '门诊口腔科'}
                ],
                signList:[
                    {id: 1, name: '上午'},
                    {id: 2, name: '下午'}
                ],
                docterList:[
                ]
            },
            methods: {
                loadPatientInfo(){
                    let url="patientServlet";
                    let param="method=getByIdCard" +
                        "&idCard="+this.registerForm.patient.idCard;
                    axios.post(url,param).then(resp=>{
                        if(resp.data.code==1001){
                            this.registerForm.patient=resp.data.patient;
                            this.registerForm.patient.sex=resp.data.patient.sex==1?"女":"男";
                        }else if(resp.data.code==1002){
                            this.$message({
                                type: 'warning',
                                message: "没有病人信息，请先创建就诊卡"
                            });
                            this.registerForm.patient={};
                        }
                    });
                },
                selectDepartment(){
                    //隐藏后面时间段、医生、医保
                    this.registerForm.sign='';
                    this.docterList=[];
                    this.registerForm.userId='';
                },
                //选择时间段
                selectSign(){
                    //隐藏后面医生、医保
                    this.docterList=[];
                    this.registerForm.userId='';

                    let url="userServlet";
                    let param="method=getDocterList" +
                        "&sign="+this.registerForm.sign+
                        "&departmentId="+this.registerForm.departmentId;
                    axios.post(url,param).then(resp=>{
                        if(resp.data.docterList.length!=0){
                            //初始化医生
                            this.docterList=resp.data.docterList;
                        }else{
                            this.$message({
                                type: 'warning',
                                message: "该时段没有就诊医师，请重新选择时段"
                            });
                        }
                    });
                },
                //选择是否医保
                selectMedicare(){
                    if(this.registerForm.isMedicare==1){
                        //设置报销金额
                        this.registerForm.medicareFee=40;
                        //从病人信息表中获取医保卡号，进行设置
                        this.registerForm.idMedicare=this.registerForm.patient.idMedicare;
                    }else if(this.registerForm.isMedicare==2){
                        this.registerForm.medicareFee=0;
                        this.registerForm.idMedicare='';
                    }
                    this.registerForm.payFee=this.registerForm.fee-this.registerForm.medicareFee;
                },
                //选择医师
                selectDoctor(){
                    this.registerForm.room='';
                    let url="patientServlet";
                    let param="method=getRoom" +
                        "&sign="+this.registerForm.sign+
                        "&departmentId="+this.registerForm.departmentId+
                        "&userId="+this.registerForm.userId;
                    axios.post(url,param).then(resp=>{
                        if(resp.data.room){
                            //初始化房间
                            this.registerForm.room=resp.data.room;
                            //初始化排期号
                            this.registerForm.scheduleId=resp.data.room.scheduleId;
                        }else{
                            this.$message({
                                type: 'warning',
                                message: resp.data.msg
                            });
                        }
                    });
                },
                createRegistry(){
                    let url="registryServlet";
                    let param="method=createRegistry" +
                        "&patientId="+this.registerForm.patient.id+
                        "&scheduleId="+this.registerForm.scheduleId+
                        "&userId="+this.registerForm.userId+
                        "&departmentId="+this.registerForm.departmentId+
                        "&roomId="+this.registerForm.room.id+
                        "&status="+this.registerForm.status+
                        "&fee="+this.registerForm.fee+
                        "&payFee="+this.registerForm.payFee+
                        "&medicareFee="+this.registerForm.medicareFee+
                        "&isMedicare="+this.registerForm.isMedicare;
                    axios.post(url,param).then(resp=>{
                        if(resp.data.code==1001){
                            this.$message({
                                type: 'success',
                                message: resp.data.msg
                            });
                        }else if(resp.data.code==1002){
                            this.$message({
                                type: 'warning',
                                message: resp.data.msg
                            });
                        }
                    });
                },
                resetForm(formName) {
                    this.$refs[formName].resetFields();
                }
            }
        }
    );
</script>
</html>